package com.itheima.Test;

import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数字：");
        while (true) {
            String str = sc.next();
            boolean flag = checkStr(str);
            if(!flag) {
                System.out.println("输入的数字有误，请重新输入");
            } else {
                String result = numberToString(str);
                System.out.println(result);
                break;
            }
        }
    }

    public static String numberToString(String str) {
        String[] luomas = {"", "Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", "Ⅶ", "Ⅷ", "Ⅸ"};
        String result = "";
        for (int i = 0; i < str.length(); i++) {
            result += luomas[str.charAt(i) - 48];
        }
        return result;
    }


    public static boolean checkStr(String str) {
        if(str.length() > 9) {
            return false;
        }
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) < '0' || str.charAt(i) > '9') {
                return false;
            }
        }
        return true;
    }
}
